package com.hornsun.repository;

import com.hornsun.domain.dbo.Slideshow;
import com.hornsun.domain.dbo.SlideshowExample;
import com.hornsun.repository.mapper.SlideshowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 编译中... on 2018/2/26.
 */
@Repository
public class SlideshowRepository {

    @Resource
    private SlideshowMapper slideshowMapper;

    /**
     * 获取轮播图
     * @return
     */
    public List<Slideshow> selectSlideshow(){
        SlideshowExample slideshowExample = new SlideshowExample();
        slideshowExample.setOrderByClause("sequence");
        return slideshowMapper.selectByExample(slideshowExample);
    }


    /**
     * 插入轮播图
     * @param slideshow
     */
    public void insertSlideshow(Slideshow slideshow){
        int count = slideshowMapper.insertSelective(slideshow);
        if (count!=1){
            throw new IllegalArgumentException("insert slideshow by slideshow:"+slideshow);
        }
    }

    /**
     * 删除轮播图
     */
    public void deleteSlideshow(){
        slideshowMapper.deleteByExample(new SlideshowExample());
    }


    public Slideshow getByGuid(String slideshowGuid){
        return slideshowMapper.selectByPrimaryKey(slideshowGuid);
    }



}
